package com.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.constant.MessageConstant;
import com.dao.MemberDao;
import com.dao.OrderDao;
import com.dao.SetmealDao;
import com.entity.Result;
import com.service.ReportService;
import com.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private SetmealDao setmealDao;
    @Override
    public Result getBusinessReportData() {
        /*reportData:{
            reportDate:null,
                    todayNewMember :0,
                    totalMember :0,
                    thisWeekNewMember :0,
                    thisMonthNewMember :0,
                    todayOrderNumber :0,
                    todayVisitsNumber :0,
                    thisWeekOrderNumber :0,
                    thisWeekVisitsNumber :0,
                    thisMonthOrderNumber :0,
                    thisMonthVisitsNumber :0,
                    hotSetmeal :[
            {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
            {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
                    ]
        }*/
        Map map=new HashMap();
        Result result=null;
        try {
            //日期存储
            String date = DateUtils.parseDate2String(new Date(), "yyyy.MM.dd");
            map.put("reportDate",date);
            //今日新增存储
            int count1=memberDao.todayNewMember(date);
            map.put("todayNewMember",count1);
            //会员总数存储
            int count2=memberDao.totalMember();
            map.put("totalMember",count2);
            //本周新增存储
            Date thisWeekMonday = DateUtils.getThisWeekMonday();
            String s = DateUtils.parseDate2String(thisWeekMonday);
            int count3=memberDao.findMemberCountAfterDate(s);
            map.put("thisWeekNewMember",count3);
            //本月新增储存thisMonthNewMember
            Date f = DateUtils.getFirstDay4ThisMonth();
            String firstDate = DateUtils.parseDate2String(f);
            int memberCountAfterDate = memberDao.findMemberCountAfterDate(firstDate);
            map.put("thisMonthNewMember",memberCountAfterDate);
            //今天预约人数todayOrderNumber
            int count4=orderDao.todayOrder(date);
            map.put("todayOrderNumber",count4);
            //今日到诊数todayVisitsNumber
            int count5=orderDao.todayVisits(date);
            map.put("todayVisitsNumber",count5);
            //本周预约数thisWeekOrderNumber
            int count6=orderDao.thisWeekOrder(s);
            map.put("thisWeekOrderNumber",count6);
            //本周到诊数
            int count7=orderDao.thisWeekVisits(s);
            map.put("thisWeekVisitsNumber",count7);
            //本月预约数thisMonthOrderNumber
            int count8 = orderDao.thisWeekOrder(firstDate);
            map.put("thisMonthOrderNumber",count8);
            //本月到访数thisMonthVisitsNumber
            int count9 = orderDao.thisWeekVisits(firstDate);
            map.put("thisMonthVisitsNumber",count9);
            //前4名热门套餐集合hotSetmeal
            //List<Map<String,Object>> list=new ArrayList<>();
            List<Map<String,Object>> ll=setmealDao.getHotSetmeamlData();
            map.put("hotSetmeal",ll);
            result=new Result(true, "查询信息成功了",map);
        } catch (Exception e) {
            e.printStackTrace();
            result=new Result(false,"查询失败了");
        }
        return result;
    }
}
